package com.lxyk.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lxyk.pojo.Customer;
import com.lxyk.pojo.Salary;
import com.lxyk.service.SalaryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/salary")
@Slf4j
public class SalaryController {

    @Autowired
    private SalaryService salaryService;

    @RequestMapping("/searchCalcSalay")
    public String listSalary(@RequestParam(required = false,defaultValue = "1",value = "pageNum")Integer pageNum,
                           @RequestParam(defaultValue = "10",value = "pageSize")Integer pageSize, Model model,
                             String startDate, String endDate){

        if (pageNum <= 0 || pageNum.equals("") || pageNum == null){
            pageNum = 1;
        }
        if (pageSize <= 0 || pageSize.equals("") || pageSize == null){
            pageSize = 10;
        }
        PageHelper.startPage(pageNum,pageSize);
        PageInfo<Salary> pageInfo = salaryService.calcSalaryByCondition(startDate, endDate, pageNum, pageSize);
        model.addAttribute("pageInfo",pageInfo);
        model.addAttribute("startDate",startDate);
        model.addAttribute("endDate",endDate);
        return "salaryList";

    }

    @RequestMapping("/searchSalay")
    public String searchSalay(@RequestParam(required = false,defaultValue = "1",value = "pageNum")Integer pageNum,
                             @RequestParam(defaultValue = "10",value = "pageSize")Integer pageSize, Model model){

        if (pageNum <= 0 || pageNum.equals("") || pageNum == null){
            pageNum = 1;
        }
        if (pageSize <= 0 || pageSize.equals("") || pageSize == null){
            pageSize = 10;
        }
        PageHelper.startPage(pageNum,pageSize);
        PageInfo<Salary> pageInfo = salaryService.calcSalary( pageNum, pageSize);
        model.addAttribute("pageInfo",pageInfo);
        return "salaryList";

    }

    @RequestMapping("/IsNullWorker")
    public String IsNullWorker(@RequestParam(required = false,defaultValue = "1",value = "pageNum")Integer pageNum,
                              @RequestParam(defaultValue = "10",value = "pageSize")Integer pageSize, Model model){

        if (pageNum <= 0 || pageNum.equals("") || pageNum == null){
            pageNum = 1;
        }
        if (pageSize <= 0 || pageSize.equals("") || pageSize == null){
            pageSize = 10;
        }
        PageHelper.startPage(pageNum,pageSize);
        PageInfo<Salary> pageInfo = salaryService.IsNullWorker( pageNum, pageSize);
        model.addAttribute("pageInfo",pageInfo);
        return "salaryList";

    }
}
